/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.ac.bath.genetic.mover;

import java.util.Collection;
import java.util.Vector;
import uk.ac.bath.genetic.base.CellFactoryIF;
import uk.ac.bath.genetic.base.Cell;
import uk.ac.bath.genetic.base.Operator;
import uk.ac.bath.genetic.base.PalleteIF;
import uk.ac.bath.genetic.base.Point;
import uk.ac.bath.genetic.bool.And;
import uk.ac.bath.genetic.bool.Cmp;
import uk.ac.bath.genetic.bool.Diff;
import uk.ac.bath.genetic.bool.Int;
import uk.ac.bath.genetic.bool.Link;
import uk.ac.bath.genetic.bool.LogicalMachine;
import uk.ac.bath.genetic.bool.Not;
import uk.ac.bath.genetic.bool.Off;
import uk.ac.bath.genetic.bool.On;

import uk.ac.bath.genetic.bool.Or;
import uk.ac.bath.genetic.bool.Palettes;
import uk.ac.bath.util.MyRandom;
import uk.ac.bath.util.Tweakable;
import uk.ac.bath.util.TweakableInt;

/**
 *
 * @author pjl
 */
public class MoverCellCTFactory implements CellFactoryIF {

    public static Vector<Tweakable> tweaks = new Vector<Tweakable>();
    public static TweakableInt maxOperatorsPerCell =
            new TweakableInt(tweaks, 10, 1000, 50, "MaxMachineSize");
    public static TweakableInt initFit =
            new TweakableInt(tweaks, 0, 200, 5, "InitialFitness");
    final public static int minOperatorsPerCell = 10;
//    static PalleteIF pallete;
//
//    static  {
//        Vector<Operator> pal = new Vector<Operator>();
//        pal.add(new And());
//        pal.add(new Or());
//        pal.add(new Not());
//        pal.add(new Link());
//        //        pallete.add(new Link());
//        // 	pallete.add(new X());
//        // 	pallete.add(new Mult());
//        pal.add(new Cmp());
//        pal.add(new On());
//        pal.add(new Off());
//        pal.add(new Diff());
//        pal.add(new Int());
//        pallete=new PalleteIF(pal);
//
//    }

    public Cell createRandomCell(Point p) {

        int nOps = minOperatorsPerCell +
                MyRandom.nextInt(maxOperatorsPerCell.intValue() - minOperatorsPerCell);
        LogicalMachine m = new LogicalMachine(nOps,Palettes.full);
        int cid = Cell.nextId();
        String tag = "MCT:" + cid;
        return new MoverCellCT(m, p,
                initFit.doubleValue() * 2.0,
                cid, 0, 0, tag);
    }

    public void mutate(Cell cell) {
         MoverCell mv=(MoverCell)cell;
        ((LogicalMachine)mv.getMachine()).mutate();
    }

    public Collection<Tweakable> getTweaks() {
       return tweaks;
    }
    
}
